<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <th:block th:include="fragments/header :: header"/>
    <script type="text/javascript" th:inline="none">

        $(function () {
            initDataGrid();
            initToolbar();
        });
        //初始化表格
        function initDataGrid() {
            $("#dgCoachList").datagrid({
                url:'/markt/coach/list',
                idField:'id',
                frozenColumns:[[
                    {field:'ck',checkbox:true}
                ]],
                columns:[[
                    {field: 'name', title: '姓名', width: 80},
                    {field: 'age', title: '年龄', width: 120}
                ]],
                pagination:true,
                rownumbers:true,
                fit:true,
                toolbar:'#dgCoachList-toolbar'
            });
        }
        //初始化工具条
        function initToolbar() {
            $("#btnAdd").click(function () {
                layer.open({
                    type:2,
                    area:['500px','300px'],
                    content:'/markt/coach/add',
                    btn:['确定','取消'],
                    yes:function (index,layero) {
                        var iframe = $(layero).find("iframe")[0].contentWindow;
                        iframe.submitForm();
                        layer.close(index);
                        window.parent.location.reload();
                    }
                });
            });

            $("#btnEdit").click(function () {
                var sel = $("#dgCoachList").datagrid('getSelected');
                if (sel) {
                    layer.open({
                        type: 2,
                        area:['500px','300px'],
                        content: '/markt/coach/edit/' + sel.id,
                        btn:['确定','取消'],
                        yes:function (index,layero) {
                            var iframe = $(layero).find("iframe")[0].contentWindow;
                            iframe.submitForm();
                            layer.close(index);
                            // $("#dgCoachList").datagrid("reload");
                            window.parent.location.reload();
                        }
                    });
                }
            });

            $("#btnRemove").click(function () {
                DataGridUtil.Delete("/markt/coach/doDelete","dgCoachList");
            });
        }
    </script>
</head>
<body class="easyui-layout">
<div id="dgCoachList-toolbar" style="padding: 2px 0;" class="datagrid-toolbar">
    <table cellpadding="0" cellspacing="0" style="width: 100%">
        <tr>
            <td style="padding-left: 2px">
                <a id="btnAdd" href="javascript:void(0)" class="easyui-linkbutton" style="float: left">新增</a>
                <a id="btnEdit" href="javascript:void(0)" class="easyui-linkbutton" style="float: left">编辑</a>
                <a id="btnRemove" href="javascript:void(0)" class="easyui-linkbutton" style="float: left">删除</a>
            </td>
        </tr>
    </table>
</div>
<div data-options="region:'center'">
    <table id="dgCoachList">

    </table>
</div>
</body>
</html>
